package com.hm.hsw4;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Demo {
    public static void main(String[] args) {
        List<Student> stuList = new ArrayList<>();
        stuList.add(new Student("张三", "男", "20", "88"));
        stuList.add(new Student("李四", "女", "19", "99"));
        try(
               FileWriter fileWriter= new FileWriter("student.txt");
                ){
            stuList.forEach(o-> {
                        try {
                            fileWriter.write(o.getName()+","+o.getSex()+","+o.getAge()+","+o.getScore()+System.lineSeparator());
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                    );

        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
